package com.zj.java21demo.exception;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import java.util.Objects;

/**
 * @Version 1.0.0
 * @Date 2024/2/28 17:39
 * @Created by zhangjun
 */
@Configuration
@Slf4j
public class CustomLogoutSuccessHandler implements LogoutSuccessHandler {
//    private TokenService tokenService;

    @SneakyThrows
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
//        LoginUserDetail loginUser = tokenService.getLoginUser(request);
//        if (Objects.nonNull(loginUser)) {
//            // 删除用户缓存记录
//            tokenService.delLoginUser(loginUser.getToken());
//        }

        log.debug("===========退出登录成功=========");

//        // 设置状态码
//        response.setStatus(HttpStatus.OK.value());
//        // 将登录失败信息打包成json格式返回
//        response.setContentType("application/json;charset=UTF-8");
//        response.getWriter().print(JsonUtil.marshal(R.success()));
    }
}
